#################################################################################
### Racialized Misinformation, Factual Corrections, and Prejudicial Attitudes ###
### [Demographic Information for Study 1]                                     ###
### Authors: Eddy S. F. Yeung, Joseph Glasgow                                 ###
### Date: June 26, 2025                                                       ###
#################################################################################

### Set-up ----
## Clean the working environment and set the working directory
rm(list = ls())
setwd("~/Desktop/racialized_misinfo/replication/Study 1") # set your working directory here, which should also contain the survey data ("study1_dataset.csv")

## Import the dataset
df <- read.csv("study1_dataset.csv")

## Load the required packages
library(tidyverse)

### Recode individual covariates ----
## Age (6 categories)
df$age <- df$age + 18
df <- df %>% 
  mutate(
    age6 = case_when(
      age >= 18 & age <= 24 ~ 1,
      age >= 25 & age <= 34 ~ 2,
      age >= 35 & age <= 44 ~ 3,
      age >= 45 & age <= 54 ~ 4,
      age >= 55 & age <= 64 ~ 5,
      age >= 65             ~ 6
    )
  )

## Ethnicity (0 = White; 1 = Black; 2 = Hispanic; 3 = other)
df <- df %>% mutate(race4 = case_when(
  race == 1 ~ 0,
  race == 2 ~ 1,
  race == 3 ~ 2,
  race >= 4 ~ 3
))

## Income (4 categories)
df <- df %>% 
  mutate(
    inc4 = case_when(
      income >= 1 & income <= 5   ~ 1,
      income >= 6 & income <= 10  ~ 2,
      income >= 11 & income <= 12 ~ 3,
      income == 13                ~ 4
    )
  )

### Analyze the demographic distributions (Table S1) ----
## Gender
with(df, table(sex)) %>% prop.table() * 100

## Age
with(df, table(age6)) %>% prop.table() * 100

## Ethnicity
with(df, table(race4)) %>% prop.table() * 100

## Income
with(df, table(inc4)) %>% prop.table() * 100
